<!DOCTYPE html>
<!-- saved from url=(0052)http://getbootstrap.com/docs/4.0/examples/dashboard/ -->
<html lang="en" xmlns:th="http://www.thymeleaf.org"
	  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<meta name="description" content="">
		<meta name="author" content="">

		<title>选课系统-老师列表</title>

		<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
		<!-- Custom styles for this template -->
		<link th:href="@{/css/dashboard.css}" rel="stylesheet">

		<script th:src="@{/js/bootstrap.min.js}"></script>
		<script type="text/javascript" th:src="@{/js/jquery-3.2.1.js}"></script>
		<script type="text/javascript">

			function queryUserIfTeacher(pageNum){
				$.ajax({
					type: "POST",
					url:"/admin/queryUserIf/teacher",
					data:{'queryCondition':$("#queryCondition").val(),'collegeId':$("#collegeId").val(),'pageNum':pageNum},
					success:function (data) {
						var tBody=$("#UserList");
						tBody.empty();//清空tbody中原有内容
						data.list.forEach((tea)=>{
							tBody.append(
									`<tr>
									<td>${tea.userId}</td>
									<td>${tea.userName}</td>
									<td>${tea.gender==0?'男':'女'}</td>
									<td>${tea.college.collegeName}</td>
									<td>
									<a class="btn btn-sm btn-primary"
									   href=${'/admin/update/'+tea.userId}>编辑</a>
									<a class="btn btn-sm btn-danger"
									   onclick="deleteUser(${tea.userId},${data.pageNum})"
									   href="#">删除</a>
									</td>
							</tr>`
							);
						});
						var paging=$("#paging");
						paging.empty();
						paging.append(
							`<ul class="paging">
								<li><a onclick="queryUserIfTeacher(${1})" href="#">首页</a></li>
								<li><a onclick="queryUserIfTeacher(${data.hasPreviousPage? data.pageNum-1 : data.pageNum})" href="#">上一页</a></li>
								<li><a>当前${data.pageNum}页 共${data.navigateLastPage}页</a></li>
								<li><a onclick="queryUserIfTeacher(${data.hasNextPage? data.pageNum+1 : data.pageNum})" href="#">下一页</a></li>
								<li><a onclick="queryUserIfTeacher(${data.navigateLastPage})" href="#">末页</a></li>
							</ul>`
						);


					},
					error : function(e){
						console.log(e.status);
						console.log(e.responseText);
					}
				});
			}


			function deleteUser(userId,pageNum){
				console.log(pageNum);
				$.ajax({
					type: "DELETE",
					url:"/admin/deleteUser",
					data:{'userId':userId},
					success:function (result) {
						console.log(result);
						queryUserIfTeacher(pageNum);
					},
					error : function(e){
						console.log(e.status);
						console.log(e.responseText);
					}
				});

			}

		</script>


	</head>

	<body>
	<div th:replace="~{commons::topbar}"></div>

		<div class="container-fluid">
			<div class="row">
				<div th:replace="~{commons::sidebar(active='teacher')}"></div>

				<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
					<div>
						请输入账号或姓名:
						<input type="text" class="search-control" id="queryCondition" placeholder="请输入账号或姓名" onchange="queryUserIfTeacher(1)">
						所属学院：
						<select class="search-control" id="collegeId" onchange="queryUserIfTeacher(1)">
							<option  value="0" selected="selected">...</option>    <!--所有学院-->
							<option th:each="college:${colleges}" th:text="${college.getCollegeName()}" th:value="${college.getCollegeId()}"></option>
						</select>
						<a class="btn btn-success"  style="float: right;margin-right:20px;" th:href="@{/admin/tomutiadd/teacher}">批量添加老师</a>
						<a class="btn btn-success"  style="float: right;margin-right:20px;" th:href="@{/admin/add/teacher}">添加老师</a>

					</div>

					<br>
					<div class="table-responsive">
						<table class="table table-striped table-sm">
							<thead>
								<tr>
									<th>账号</th>
									<th>姓名</th>
									<th>性别</th>
									<th>所属学院</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody id="UserList">
								<tr th:each="tea:${teachers.getList()}">
									<td th:text="${tea.getUserId()}"></td>
									<td th:text="${tea.getUserName()}"></td>
									<td th:text="${tea.getGender()==0? '男' : '女'}"></td>
									<td th:text="${tea.getCollege().getCollegeName()}"></td>
									<td>
										<a class="btn btn-sm btn-primary" th:href="@{'/admin/update/'+${tea.getUserId()}}">编辑</a>
										<a class="btn btn-sm btn-danger" th:href="|javascript:deleteUser(${tea.getUserId()},${teachers.pageNum})|">删除</a>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
					<div id="paging">
						<ul class="paging"  >
							<li><a th:href="|javascript:queryUserIfTeacher(1)|">首页</a></li>
							<li><a th:href="|javascript:queryUserIfTeacher(${teachers.hasPreviousPage? teachers.pageNum-1 : teachers.pageNum})|">上一页</a></li>
							<li><a>当前[[${teachers.pageNum}]]页 共[[${teachers.navigateLastPage}]]页</a></li>
							<li><a th:href="|javascript:queryUserIfTeacher(${teachers.hasNextPage? teachers.pageNum+1 : teachers.pageNum})|">下一页</a></li>
							<li><a th:href="|javascript:queryUserIfTeacher(${teachers.navigateLastPage})|">末页</a></li>
						</ul>
					</div>
				</main>
			</div>
		</div>

	</body>

</html>